package Features.RatFeild
{
	import com.greensock.TweenLite;
	
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.Event;
	
	import org.SFramework.Core.SFramework;
	
	public class RatHog extends Sprite
	{
		private var mcCave:MovieClip;		
		public var showTime:Number;
		
		public function RatHog()
		{
			super();
		
			mcCave				=	SFramework.singleton.resourceManager.getImmediateResourceInst( Assets.assetsSwfName, "cave" );
			addChild( mcCave );
			
			mcCave.gotoAndStop( "stop" );
		}
		
		public function doPopup( sTime:Number, e:Boolean=true ):void
		{
			mcCave.gotoAndPlay( "popup" );
			showTime	=	sTime;
			enabled		=	e;
		}
		
		public function doWhack():int
		{
			mcCave.gotoAndPlay( "whack" );
			enabled		=	false;
			
			return 1;
		}
		
		public function doHide():void
		{
			mcCave.gotoAndPlay( "hide" );
		}
		
		public function set enabled( val:Boolean ):void
		{
			mouseEnabled	=	val;
			mouseChildren	=	val;
		}
		
		public function applySmoke():void
		{
			var smoke:MovieClip	=	SFramework.singleton.resourceManager.getImmediateResourceInst( Assets.assetsSwfName, "smoke" );
			addChild( smoke );
			smoke.gotoAndPlay( 1 );
			smoke.addEventListener( Event.ENTER_FRAME, handleEnterFrame );
			
			function handleEnterFrame(e:Event):void
			{
				if( smoke.currentFrame >= 12 )
				{
					TweenLite.delayedCall( 1, removeSmoke, null, true );
					smoke.removeEventListener( Event.ENTER_FRAME, handleEnterFrame );
				}				
			}
			
			function removeSmoke():void
			{
				removeChild( smoke );
			}
		}
	}
}